package com.mox.enterprise.factory;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author mox
 * @time 2020/2/18 14:30
 */

@Slf4j
public class SqlSessionFactoryUtil {

    public static SqlSessionFactory sessionFactory = null;

    public SqlSessionFactoryUtil() {
    }

    static {
        String resource = "mybatis-config.xml";
        try {
            InputStream ins = Resources.getResourceAsStream(resource);
            sessionFactory = new SqlSessionFactoryBuilder().build(ins);
            log.info("sql session 获取成功");
        } catch (IOException e) {
            log.error("sql session获取失败:{}", e.getMessage());
        }
    }

}
